package model;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author  Owner
 */
public abstract class Sorter {
    
    protected Statistics statistics;
    
    private ArrayBlockingQueue<DrawCommand> queue;

    protected int[] workArray;

    protected boolean simulation = false;

    public static final int SELECTION = 0;

    public static final int BUBBLE = 1;

    public static final int SHELL = 2;

    public static final int INSERTION = 3;

    public static final int MERGE = 4;

    public static final int QUICK = 5;

    public static final int HEAP = 6;

    public Sorter() {
    }

    @SuppressWarnings("unchecked")
	public abstract void sort(Comparable[] workArray);

    /**
	 * sets the specified queue to be used as command memory
	 * @param  queue
	 * @uml.property  name="queue"
	 */
    public void setQueue(ArrayBlockingQueue<DrawCommand> queue) {
	this.queue = queue;
    }

    /**
         * Adds a swap to visual memory to be drawn later by a Thread
         * 
         * @param a
         *                element to be swapped
         * @param b
         *                element that a swapped with
         */
    protected void PushSwapToQueue(int a, int b) {
	try {
	    queue.put(new DrawCommand(a, b ,null));
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}
    }

    protected void PushMergeListToQueue(Integer[] mergeArray) {
		try {
			queue.put(new DrawCommand(0, 0, mergeArray));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

    public void setSimulated(boolean simulation) {
	this.simulation = simulation;
    }
    
    public abstract int getComplexity(int arraySize);
    /**
	 * @return  the statistics
	 * @uml.property  name="statistics"
	 */
    public Statistics getStatistics(){
	return this.statistics;
    }
}
